import 'package:enjoy_plus/pages/home/components/home_list.dart';
import 'package:enjoy_plus/pages/home/components/home_nav.dart';
import 'package:enjoy_plus/utils/Toast.dart';
import 'package:enjoy_plus/utils/http.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

// 有状态的组件
class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  // 状态变量
  List notifyList = [];

  // 获取数据
  getData() async {
    // 获取 设置公告数据
    final res = await http.get('/announcement');
    print(res['data']);
    // 更新 ui
    setState(() {
      notifyList = res['data'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color.fromARGB(40, 85, 145, 175),
        appBar: AppBar(
          title: const Text('享+社区'),
          backgroundColor: Colors.transparent,
          centerTitle: true,
        ),
        body: ListView(
          scrollDirection: Axis.vertical,
          padding: const EdgeInsets.all(10),
          children: [
            // 导航条
            HomeNav(),
            // 中间广告图
            ClipRRect(
              borderRadius: BorderRadius.circular(10.0),
              child: GestureDetector(
                onTap: () {
                  ToastUtil.showInfo('点了图片');
                },
                child: Image.asset('images/banner@2x.jpg'),
              ),
            ),
            // 社区公告
            HomeList(
              notifyList: notifyList,
            )
          ],
        ));
  }
}
